
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  validation;

import java.util.*;

import logger.PoolLogger;

import dbmanager.DBManager;

import utility.DateConversion;

public class Datedispatch implements Validation
{

	DateConversion mydt = new DateConversion();
	Calendar clndr = new GregorianCalendar();
	
	boolean FLAGE;
	PoolLogger pl;
	
	public Datedispatch() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}
	
	public boolean validate(String Value){
		 //------------get current date in seperate variables -------------------
		 int currentday = clndr.get(Calendar.DAY_OF_MONTH);
		 int currentmonth = clndr.get(Calendar.MONTH)+1;
		 int currentyear = clndr.get(Calendar.YEAR);
		 
		 //------------ see the current date -------------------------------------
		 System.out.println("YEAR: " + currentyear);
		 System.out.println("MONTH: " + currentmonth);
		 System.out.println("DAY: " + currentday);
		 
			pl.info("YEAR: " + currentyear);
			pl.debug("YEAR: " + currentyear);
			pl.warn("YEAR: " + currentyear);
			pl.fatal("YEAR: " + currentyear);
			pl.error("YEAR: " + currentyear);
			pl.trace("YEAR: " + currentyear);
			
			pl.info("MONTH: " + currentmonth);
			pl.debug("MONTH: " + currentmonth);
			pl.warn("MONTH: " + currentmonth);
			pl.fatal("MONTH: " + currentmonth);
			pl.error("MONTH: " + currentmonth);
			pl.trace("MONTH: " + currentmonth);
			
			pl.info("DAY: " + currentday);
			pl.debug("DAY: " + currentday);
			pl.warn("DAY: " + currentday);
			pl.fatal("DAY: " + currentday);
			pl.error("DAY: " + currentday);
			pl.trace("DAY: " + currentday);
			
		 //------------see in date format of your date -------------------------
		 System.out.print ("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			pl.info("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			pl.debug("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			pl.warn("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			pl.fatal("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			pl.error("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			pl.trace("Date : "+mydt.getDate(Value,"YYYY-MM-DD"));
			 
		 //------------getting your date in seperate variables and print variables-----------------
		 int day = mydt.getDay(Value);
		 int month = mydt.getMonth(Value);
		 int year = mydt.getYear(Value);
		 
		 System.out.println ("Printing it serially !");
			pl.info("Printing it serially !");
			pl.debug("Printing it serially !");
			pl.warn("Printing it serially !");
			pl.fatal("Printing it serially !");
			pl.error("Printing it serially !");
			pl.trace("Printing it serially !");
		 System.out.println ("Date = "+day+", Month = "+month+", Year = "+year);
			pl.info("Date = "+day+", Month = "+month+", Year = "+year);
			pl.debug("Date = "+day+", Month = "+month+", Year = "+year);
			pl.warn("Date = "+day+", Month = "+month+", Year = "+year);
			pl.fatal("Date = "+day+", Month = "+month+", Year = "+year);
			pl.error("Date = "+day+", Month = "+month+", Year = "+year);
			pl.trace("Date = "+day+", Month = "+month+", Year = "+year);
		 		 
		 //---------------- now ONLY compare variables of your date and current date -----------------------------------------		 
		
		 if (year<currentyear)
		 {
			 return true;
		 }
		 else if (year==currentyear)
		{
			if (month<currentmonth)
			{
				return true;
			}
			else if (month==currentmonth)
			{
				if (day<=currentday)
				{
					
					return true;
				}
				else if (day>currentday)
				{
					return false;
				}
			}
		 }
	return false;
	}	
	
	public static void main(String[] args) {
		
		Datedispatch dd = new Datedispatch();
		
	    boolean chkdt = dd.validate("30042007");
		
		System.out.println(chkdt);		
	}

	public boolean validate(String Value, String conditionValue) {
		// TODO Auto-generated method stub
		return false;
	}

	public String getMessage() {
		// TODO Auto-generated method stub
		pl.info("The delivery date must not be greter than current date.");
		pl.debug("The delivery date must not be greter than current date.");
		pl.warn("The delivery date must not be greter than current date.");
		pl.fatal("The delivery date must not be greter than current date.");
		pl.error("The delivery date must not be greter than current date.");
		pl.trace("The delivery date must not be greter than current date.");
		return "The delivery date must not be greter than current date.";
		
	}

	public void initPool() {
		// TODO Auto-generated method stub
		
	}

	public boolean validate(String Value, String ConditionValue, String Refvalue) {
		// TODO Auto-generated method stub
		return false;
	}

	public void setBasicvalue(String value) 
	{
	
		
	}
}
